]> git.r.bdr.sh - rbdr/captura/blob - Captura/Core Extensions/CVImageBuffer+cgImage.swift
Add multimonitor support
[rbdr/captura] / Captura / Core Extensions / CVImageBuffer+cgImage.swift
1 import Foundation
2 import ReplayKit
3
4 extension CVImageBuffer {
5
6 private static let contextQueue = DispatchQueue(label: "com.example.contextQueue")
7 static let sharedContext: CIContext = {
8 return CIContext()
9 }()
10
11 var cgImage: CGImage? {
12 var result: CGImage?
13 CVImageBuffer.contextQueue.sync {
14 let ciImage = CIImage(cvImageBuffer: self)
15 let width = CVPixelBufferGetWidth(self)
16 let height = CVPixelBufferGetHeight(self)
17 result = CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height))
18 }
19 return result
20 }
21 }